home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
STANDALO
/
SHOWINIT
/
TEST.C
< prev
Wrap
C/C++ Source or Header
|
1990-07-29
|
3KB
|
115 lines
/*
init test.c : Entry point for INIT
*/
/*
Notes:
This stuff is LightSpeed C specific. Other compilers don't allow
globals in INITs or CODE resources. Remove globals & A4 reference
for other compilers.
Set File type to 'INIT' and put in System Folder.
Use ResEdit or LSC to lock the 'INIT' resource.
Use ResEdit or LSC to set the System Heap bit.
Call DetachResource if we want to stay in memory. See the
Tech Notes for details on allocating storage space. Inside
Mac V has a new way for keeping us around too. I think we'd
have to set the SYS bit of our resource too.
Stealing a trap and pointing it to our routine works ok.
Globals are passed in as a0 on startup. CODE resources use globals from
A4, so we set A4 to point to globals and restore it when done.
(LSC handles everything else). LSC 3.0 has new macros for
initializing A4. See <SetUpA4.h>. The macros work as follows:
__GetA4() - Puts address of 4 bytes of storage
into A1 (static function).
RememberA0() - A0 -> Storage
RememberA4() - A4 -> Storage
SetUpA4() - Push A4, Storage -> A4
RestoreA4() - Pop A4
We must initialize toolbox. The only hard one is QuickDraw, since
thePort isn't correct here. We╒ll allocate a record of size
GrafSize and pass the address of the last field (thePort) to
InitGraf.
Initializing the Window Manager will erase the screen. This would prevent
us from showing an INIT icon (we'd clear other icons). A #define
controls this.
*/
#include "init.h"
#ifndef APPLICATION
static QD_GLOBALS our_qd;
#endif
void main()
{
Handle self_handle; /* a handle to our own code resource */
#ifndef APPLICATION
CODE_SETUP(); /* push registers to stack, setup A4 */
/* be 100% sure we're locked down. See LSC 3.0 manual p.86 */
asm
{
_RecoverHandle ;A0 already set up
move.l a0, self_handle ;
}
HLock(self_handle);
#ifdef PERMANENT
DetachResource(self_handle); /* so we'll stay after file closed */
#endif /* PERMANENT */
#endif /* APPLICATION */
init_mac(); /* initialize toolbox */
#ifndef APPLICATION
show_init_icon(300, -1); /* put the icon on the screen */
#endif
load_it(); /* steal the trap */
/* other trap patches go here */
unload_it();
#ifndef APPLICATION
CODE_CLEANUP(); /* restore the registers */
#endif
}
/*
init_mac : Initializes Mac toolbox
Note:
Initialization depends on APPLICATION and INIT_ALL #defines
If not an application, INIT_ALL #define means to
initialize all toolbox managers. This will erase
the screen, though.
*/
init_mac()
{
#ifdef APPLICATION
InitGraf(&thePort);
InitFonts();
InitWindows();
InitCursor();
InitMenus();
InitDialogs (0L);
TEInit();
#else
InitGraf(&our_qd.thePort);
#ifdef INIT_ALL
DeskHook = 0;
DragHook = 0;
InitFonts();
InitWindows();
InitCursor();
InitMenus();
InitDialogs(NULL);
TEInit();
#endif /* INIT_ALL */
#endif /* not APPLICATION */
FlushEvents(everyEvent, 0);
}